<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Delete User Profile</title>
</head>
<body>

    <h2>Delete User Profile</h2>
    <p>Please enter the user ID to delete:</p>

    <form id="deleteForm">
        <input type="text" id="userIdInput" placeholder="User ID" required>
        <button type="submit">Delete</button>
    </form>

    <script>
        // 定义删除用户信息的函数
        async function deleteUserProfile(userId) {
            const url = 'http://127.0.0.1:8888/UserProfile_delete'; // 假设这是后端接口的URL
            const data = { user: userId };
            console.log(userId);

            try {
                const response = await fetch(url, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(data)
                });

                if (!response.ok) {
                    throw new Error(`HTTP error! status: ${response.status}`);
                }

                const result = await response.json();
                console.log('Delete operation result:', result);
                alert('User profile deleted successfully.'); // 可以弹窗提示用户操作结果
            } catch (error) {
                console.error('There was a problem with the fetch operation:', error);
                alert('An error occurred while deleting the user profile.'); // 弹窗提示错误
            }
        }

        // 添加事件监听器到表单的提交事件
        document.getElementById('deleteForm').addEventListener('submit', async (event) => {
            event.preventDefault(); // 阻止表单默认提交行为
            const userId = document.getElementById('userIdInput').value;
            await deleteUserProfile(userId); // 调用删除用户信息的函数
        });
    </script>

</body>
</html>
